package com.gem.mapper;

import com.gem.domain.User;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: 玲
 * @Description:
 * @create 2019-10-25 15:32
 * @Modified By:
 */
@Mapper
public interface UserMapper {

    /**
     * 根据id查询
     */
    @Select("select * from user where uid = #{uid} AND status > 0")
    User findById(Integer uid);

    /**
     * 根据名字查询
     */
    @Select("select * from user where personname = #{personname} AND status > 0")
    User findByName(String personname);

    /**
     * 根据名字查询(市场部)
     */
    @Select("select * from user where personname = #{personname} AND department = '市场' AND status >= 0")
    User findByNameWithM(String personname);

    /**
     * 添加用户
     */
    Integer save(User user);

    /**
     * 根据id删除用户
     */
    @Delete("UPDATE user SET status = -1 WHERE uid = #{uid}")
    Integer deleteById(Integer uid);

    /**
     * 修改密码
     */
    @Update("update user set password = #{password} where uid = #{uid} AND status > 0")
    Integer updatePassword(@Param("password") String password, @Param("uid") Integer uid);

    /**
     * 查询渠道/咨询人员(市场)
     */
    @Select("select * from user where department = '市场' and authority = 3 AND status > 0 ")
    List<User> findMmembers();

    //实训订单渠道专员专用！（增加无这个选项）
    @Select("select * from user where department = '市场' and authority = 3 AND status >= 0 ")
    List<User> findMmembersWithNull();

    //模糊查询渠道、咨询人员
    @Select("SELECT * FROM user WHERE department = '市场' AND authority = 3 AND personname LIKE CONCAT('%',#{dsSeller},'%') AND status > 0")
    List<User> findMmembersByPersonName(String dsSeller);

    //模糊查询渠道、咨询人员
    @Select("SELECT * FROM user WHERE job = '企培' AND authority = 3 AND personname LIKE CONCAT('%',#{crSales},'%') AND status > 0")
    List<User> findMmembersBySalesName(String crSales);

    /**
     * 查询销售人员
     */
    @Select("select * from user where department = 'hrc' and job = '企培' and authority = 3 AND status > 0 ")
    List<User> findEmembers();

    /**
     * 查询就业人员/推荐老师
     */
    @Select("select * from user where department = 'hrc' and job = '就业' and authority = 3 AND status > 0 ")
    List<User> findJmembers();

    /**
     * 查询就hrc所有
     */
    @Select("select * from user where department = 'hrc' AND status > 0 ")
    List<User> findHrc();

    //登录
    @Select("select * from user where username = #{username} and password = #{password} AND status >= 0")
    User login(User user);

    /**
     * @Description: 增加人员维护的方法
     * @create 2019-11-1
     * @Modified By: Bravea❤ ·勇
     */
    //查询用户通过名字
    @Select("select * from user where username = #{username} AND status > 0")
    User findByUsername(User user);

    //查询所有用户
    @Select("select * from user where status > 0")
    List<User> findAllUser();

    //查询所有市场（包括老大)
    @Select("select * from user where department = '市场' AND status > 0 ")
    List<User> findAllMmembers();

    //查询所有就业（包括老大）
    @Select("select * from user where department = 'hrc' and job = '就业' AND status > 0 ")
    List<User> findAllJmembers();

    //查询所有企培（包括老大）
    @Select("select * from user where department = 'hrc' and job = '企培' AND status > 0 ")
    List<User> findAllEmembers();

    //修改用户信息
    @Update("update user set department = #{department}, job = #{job}, authority = #{authority}, remark = #{remark} where uid = #{uid} AND status > 0")
    boolean modifyUser(User u);

    //模糊查询用户
    @Select("select * from user where personname like #{personname} AND status > 0")
    List<User> findUserByName(String personname);

    //查找其他
    @Select("select * from user where department = '其他' AND authority > 1 AND status > 0 ")
    List<User> findOther();
}
